﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AIMLBot;

namespace SurvivalStrategy.Entities.ConversationData
{
    public class Chat
    {
        public bool started = false;
        Character chara1;
        Character chara2;
        Entity entity1;
        Entity entity2;
        int turn;
        string currentLine;

        public Chat(Entity entity1, Entity entity2)//<string> files1, List<string> files2)
        {
            List<string> files1 = entity1.GetComponent<ConversationComponent>().AIMLFiles;
            List<string> files2 = entity2.GetComponent<ConversationComponent>().AIMLFiles;

            this.entity1 = entity1;
            this.entity2 = entity2;

            chara1 = new Character(files1, this);
            chara2 = new Character(files2, this);

            turn = 2;

            if (entity1.GetComponent<ConversationComponent>().StartConverstation())
                if (entity2.GetComponent<ConversationComponent>().StartConverstation())
                    chara1.Init();
        }

        public bool talk(string question)
        {
            if (question == "Do widzenia")
                if (entity1.GetComponent<ConversationComponent>().EndConverstation())
                    if (entity2.GetComponent<ConversationComponent>().EndConverstation())
                        return true;

            if (turn == 1)
            {
                currentLine = chara1.Reply(question);
                turn = 2;
            }
            else if (turn == 2)
            {
                currentLine = chara2.Reply(question);
                turn = 1;
            }
            return false;
        }

        public bool Update()
        {
            return talk(currentLine);
        }
    }
}
